package com.hrt.manage.stock.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hrt.bean.StockDetail;
import com.hrt.manage.stock.dao.StockDao;
import com.hrt.manage.stock.dao.StockDetailDao;
import com.hrt.manage.stock.service.StockDetailService;
import com.hrt.vo.StockDetailVO;

@Service
public class StockDetailServiceImpl implements StockDetailService {

	
	@Autowired
	private StockDetailDao detailDao;
	
	@Autowired
	private StockDao stockDao;

	@Override
	@Transactional
	public boolean delItemById(Long itemId) {
		// TODO Auto-generated method stub
		StockDetail item=detailDao.getById(itemId);
		if(item!=null){
		item.setIsdelete(new Integer(1));
		detailDao.updateEntity(item);
		
		return true;
		}
		return false;
	}

	@Override
	public StockDetailVO getDetailById(Long itemId) {
		// TODO Auto-generated method stub
		StockDetail d= detailDao.getById(itemId);
		StockDetailVO vo = new StockDetailVO();
		vo.setCreateTime(d.getCreateTime()==null?null:d.getCreateTime());
		vo.setCreator(d.getCreator());
		vo.setEditor(d.getEditor());
		vo.setEditTime(d.getEditTime()==null?null:d.getEditTime());
		vo.setEnterPrice(d.getEnterPrice());
		vo.setId(d.getId());
		vo.setIsdelete(d.getIsdelete());
		vo.setNote(d.getNote());
		vo.setProCode(d.getProCode());
		vo.setProId(d.getProId());
		vo.setProName(d.getProName());
		vo.setReType(d.getReType());
		vo.setSalePrice(d.getSalePrice());
		vo.setRuleCode(d.getRuleCode());
		vo.setRuleName(d.getRuleName());
		vo.setCreateTime(d.getCreateTime());
		vo.setCreateTime(d.getCreateTime());
		vo.setRuleId(d.getRuleId());
		vo.setSummery(d.getSummery());
		vo.setTotal(d.getTotal());
		return vo;
	}

	@Override
	public List<StockDetailVO> getDetailByStockId(Long stockId,Integer pageIndex,Integer pageSize) {
		// TODO Auto-generated method stub
		List<StockDetail> list = detailDao.getDetialsByStockId(stockId, pageIndex, pageSize);
				List<StockDetailVO> vos = new ArrayList<StockDetailVO>();
				if(list!=null && !list.isEmpty()){
				for (StockDetail d : list) {
					StockDetailVO vo = new StockDetailVO();
					vo.setCreateTime(d.getCreateTime());
					vo.setCreator(d.getCreator());
					vo.setEditor(d.getEditor());
					vo.setEditTime(d.getEditTime());
					vo.setEnterPrice(d.getEnterPrice());
					vo.setId(d.getId());
					vo.setIsdelete(d.getIsdelete());
					vo.setNote(d.getNote());
					vo.setProCode(d.getProCode());
					vo.setProId(d.getProId());
					vo.setProName(d.getProName());
					vo.setReType(d.getReType());
					vo.setSalePrice(d.getSalePrice());
					vo.setRuleCode(d.getRuleCode());
					vo.setRuleName(d.getRuleName());
					vo.setCreateTime(d.getCreateTime());
					vo.setCreateTime(d.getCreateTime());
					vo.setRuleId(d.getRuleId());
					vo.setSummery(d.getSummery());
					vo.setTotal(d.getTotal());
					vos.add(vo);
	}
				}
				return vos;
}

	@Override
	public List<StockDetailVO> getDetailByStockId(Long stockId) {
		// TODO Auto-generated method stub
		List<StockDetailVO>  vos=new ArrayList<StockDetailVO>();
		List<StockDetail>  entryList=new ArrayList<StockDetail>();
		entryList=this.detailDao.getDetailsByStockId(stockId);
		if(entryList!=null && !entryList.isEmpty())
		{
			for(StockDetail d:entryList){
				StockDetailVO vo=new StockDetailVO();
				vo.setCreateTime(d.getCreateTime());
				vo.setCreator(d.getCreator());
				vo.setEditor(d.getEditor());
				vo.setEditTime(d.getEditTime());
				vo.setEnterPrice(d.getEnterPrice());
				vo.setId(d.getId());
				vo.setIsdelete(d.getIsdelete());
				vo.setNote(d.getNote());
				vo.setProCode(d.getProCode());
				vo.setProId(d.getProId());
				vo.setProName(d.getProName());
				vo.setReType(d.getReType());
				vo.setSalePrice(d.getSalePrice());
				vo.setRuleCode(d.getRuleCode());
				vo.setRuleName(d.getRuleName());
				vo.setCreateTime(d.getCreateTime());
				vo.setCreateTime(d.getCreateTime());
				vo.setRuleId(d.getRuleId());
				vo.setSummery(d.getSummery());
				vo.setTotal(d.getTotal());
				vos.add(vo);
			}
		}
		return vos;
	}
}
